package com.zqc.task;

import com.zqc.bean.ServiceComponent;

/**
 * 消费端线程任务
 */
public class ConsumerTask implements Runnable {
    private ServiceComponent serviceComponent;
    private String sign;

    public ConsumerTask(ServiceComponent serviceComponent, String sign) {
        this.serviceComponent = serviceComponent;
        this.sign = sign;
    }

    @Override
    public void run() {
        while (true) {
            callMethod();
        }
    }

    /**
     * 执行调用
     */
    private void callMethod() {
        if ("A".equalsIgnoreCase(this.sign)) {
            this.serviceComponent.methodA();
        } else if ("B".equalsIgnoreCase(this.sign)) {
            this.serviceComponent.methodB();
        } else if ("C".equalsIgnoreCase(this.sign)) {
            this.serviceComponent.methodC();
        } else {
            throw new RuntimeException("未知的消费标识【" + this.sign + "】");
        }
    }
}
